<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: xsh
  Date: 2019/10/25
  Time: 15:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>Title</title>
        <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"/>
        <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    </head>
    <body>
        <form class="form-horizontal" id="updateForm">
            <div class="form-group">
                <label for="goodsName" class="col-sm-2 control-label">商品名称：</label>
                <div class="col-sm-10">
                    <input type="text" name="goodsName" value="${goods.goodsName}" placeholder="请输入商品名称" class="form-control" id="goodsName">
                </div>
            </div>
            <div class="form-group">
                <label for="price" class="col-sm-2 control-label">价格：</label>
                <div class="col-sm-10">
                    <input type="text" name="price" value="${goods.price}" placeholder="请输入商品价格" class="form-control" id="price">
                </div>
            </div>
            <div class="form-group">
                <label for="typeName" class="col-sm-2 control-label">商品类型：</label>
                <div class="col-sm-10">
                    <select name="typeName" id="typeName">
                        <option value="${goods.typeName}">${goods.typeName}</option>
                        <c:forEach var="goodsType" items="${goodsTypes}">
                            <option value="${goodsType}">${goodsType}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="description" class="col-sm-2 control-label">商品描述：</label>
                <div class="col-sm-10">
                    <input type="text" name="description" value="${goods.description}" placeholder="请输入商品描述" class="form-control" id="description">
                </div>
            </div>
            <div class="form-group">
                <label for="date" class="col-sm-2 control-label">上架日期：</label>
                <div class="col-sm-10">
                    <input type="text" name="date" value="${goods.date.toLocaleString()}" placeholder="请输入上架日期" class="form-control" id="date">
                </div>
            </div>
            <div class="form-group">
                <label for="stars" class="col-sm-2 control-label">商品星级：</label>
                <div class="col-sm-10">
                    <input type="text" name="stars" value="${goods.stars}" placeholder="请输入商品星级" class="form-control" id="stars">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <input type="button" value="更新" class="btn btn-default" id="update">
                    <a href="${pageContext.request.contextPath}/index">返回首页</a>
                </div>
            </div>
        </form>
    </body>
    <script>

        $("#update").click(function () {
            $.ajax({
                url:"${pageContext.request.contextPath}/goods/update",
                type:"put",
                data:JSON.stringify({
                    "id":${goods.id},
                    "goodsName":$("#goodsName").val(),
                    "price":$("#price").val(),
                    "typeName":$("#typeName").val(),
                    "description":$("#description").val(),
                    "date":$("#date").val(),
                    "stars":$("#stars").val()
                }),
                success:function () {
                    document.location.href = "${pageContext.request.contextPath}/goods/list";
                },
                contentType:"application/json"
            })
        })
    </script>
</html>
